/**
 * 扬尘警报预警参数配置（添加|修改）dustAlarmConfigOption.js
 * 版本号： v1.0.0
 */
$(function(){

    //限制字段输入长度
    limitFieldLength();

    // 公司下拉树
    $('#companyTree').combotree({
        url: CONTEXT_PATH + "/company/getTreeCompany.do",
        required:true,
        onChange:function(newCpId,oldCpId){
            $('#companyId_').val(newCpId);
            if(newCpId){
                bindCombo_projectSel(newCpId);
            }
        }
    });

    //操作按钮点击
    $('#optionDustAlarmConfig').bind('click', function(){
        var params = $("#dustAlarmConfig_form").serialize();
        $("#dustAlarmConfig_form").form("submit",{
            cache:false,
            data: params,
            url: CONTEXT_PATH + "/dustAlarmConfig/save.do",
            onSubmit:function() {
                preventSubmit('dustAlarmConfig_form','optionDustAlarmConfig');
                return $(this).form("validate");
            },
            success:function(data) {
                var obj = JSON.parse(data);
                var url = CONTEXT_PATH + "/dustAlarmConfig/index.do";
                saveJump(obj,url);
            }
        });
    });

});

/**
 * 所属项目bind事件
 * @param deviceControl
 */
function bindCombo_projectSel(companyId){
    $("#prId").combobox("clear");
    $.ajax({
        url: CONTEXT_PATH + "/project/getProjectListForCombo.do?companyId="+companyId,
        type: "get",
        success: function (data) {
            var obj = JSON.parse(data);
            var projectCombo = [{'text': '--请选择--','value': ''}];
            for (var i = 0; i < obj.length; i++) {
                projectCombo.push({"text": obj[i].prName, "value": obj[i].prId});
            }
            $("#prId").combobox("loadData", projectCombo);
            $("#prId").combobox({
                required:true,
                onSelect: function(rec){
                    $('#prId_').val(rec.value);
                }
            });
            var prId = $('#prId_').val();
            if(prId){
                $("#prId").combobox("setValue", prId);
            }else{
                $("#prId").combobox("setValue", '');
            }
        }
    })
}

window.onload=function(){
    //修改操作时，数据加载完成后公司赋值
    var companyId =$('#companyId_').val();
    if(companyId != null && companyId != 0){
        $('#companyTree').combotree('setValue', companyId);
    }
}

